package com.chenyue.cm.bean;

import com.chenyue.cm.common.constant.ConstantValues;
import com.chenyue.cm.utils.DateUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

@Data
public class CodeMakerBean {

	private String author ;
	private String dateTime ;
	private String describe ;
	private String moudule ;
	private String tablename ;// sys_user
	private String tablename_lowerCase ;// sysuser
	private String tablename_uperCase ;// SysUser
	private String tablename_camelCase ;// sysUser
	List<ColumnBean> columns;


	private Boolean cmUpload = false ;//是否引入单图上传组件
	private Boolean cmUploadMore = false ;//是否引入多图上传组件
	private Boolean cmRichText  =false ;//是否引入富文本


	/**
	 *
	 * @param tablename
	 * @param columnlist
	 */
	public CodeMakerBean(String tablename,Map<String, Object> paramMap, List<Map<String, Object>> columnlist) {
		super();
		//封装返回参数
		List<ColumnBean>  resultList = new ArrayList<>();
		for (Map<String, Object> map : columnlist) {
			// 根据传参解析 列字段 类型
			ColumnBean  cBean = new ColumnBean(map);

			if( "3".equals( cBean.getFORM_SHOW_TYPE() )  ){
				this.cmUpload =true;
			}
			if( "31".equals( cBean.getFORM_SHOW_TYPE() )  ){
				this.cmUploadMore =true;
			}
			if( "8".equals( cBean.getFORM_SHOW_TYPE() )  ){
				this.cmRichText =true;
			}

			resultList.add(cBean);
		}
		this.author = "chenyue-cm";
		this.dateTime  = DateUtils.getTodayStr();
		this.describe = paramMap.get("describe").toString();
		this.moudule = paramMap.get("moudule").toString();
		this.tablename = tablename;
		this.tablename_lowerCase = underlineToCamel(tablename).toLowerCase(); // 表名小写
		this.tablename_uperCase  = underlineToCamel("_"+tablename); // 表名大写
		this.tablename_camelCase = underlineToCamel(tablename); // 表名驼峰命名
		this.columns = resultList;

	}

	
	 /**
     * 下划线格式字符串转换为驼峰格式字符串
     * 
     * @param param
     * @return
     */
    public static String underlineToCamel(String param) {
    	 if (param == null || "".equals(param.trim())) {
             return "";
         }
        StringBuilder sb = new StringBuilder(param);
        Matcher mc = ConstantValues.COMPILE_WITH_.matcher(param);
        int i = 0;
         while (mc.find()) {
             int position = mc.end() - (i++);
             sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
         }
         return sb.toString();
    }

	
	
}
